﻿using FySystem.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FySystem.Entity.Common
{
    /// <summary>
    /// 返回结果类型，如果Data为null，当类型为Single时，返回的Json中Data为{}，当类型为Array时，返回的Json中Data为[]
    /// </summary>
    public enum EResultType
    {
        Single, Array
    }

    /// <summary>
    /// 通用数据返回实体
    /// </summary>
    public class ResultDTO
    {
        public int Status { get; set; } = 0;

        public string Message { get; set; } = "";

        public object Data { get; set; }

        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="resultType"></param>
        public ResultDTO()
        {
        }

        /// <summary>
        /// 设置错误消息
        /// </summary>
        /// <param name="msg"></param>
        public void SetErrorMessage(Exception exception)
        {
            try
            {
                FyException fyEx = (FyException)exception;
                Status = fyEx.Code;
                Message = fyEx.Message;
            }
            catch
            {
                Status = 1;
                Message = exception.Message;
            }
        }
    }
}
